package longrise.phone.com.bjjt_henan.main;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.longrise.android.FormParameter;
import com.longrise.android.LFView;

import longrise.phone.com.bjjt_henan.R;

/**
 * 操作演示界面
 */
public class ActionDemoView extends LFView implements View.OnClickListener {
    private Context context = null;
    private View view = null;
    private LinearLayout backLayout;
    private LinearLayout consultLayout;
    private LinearLayout policeLayout;

    public ActionDemoView(Context c) {
        super(c);
        context = c;
    }

    @Override
    public FormParameter getFormParameter() {
        FormParameter parameter = new FormParameter();
        parameter.setShowtitle(false);
        return parameter;
    }

    @Override
    public View getView() {
        return view;
    }

    @Override
    public void init() {
        if (null == context) {
            return;
        }
        view = LayoutInflater.from(context).inflate(R.layout.demo_view,
                null);
        if (null == view) {
            return;
        }
        TextView titleTView = (TextView) view.findViewById(R.id.tv_title);
        titleTView.setText("操作演示");
        backLayout = (LinearLayout) view.findViewById(R.id.hn_btn_back);
        consultLayout = (LinearLayout) view.findViewById(R.id.demo_llayout_consult);
        policeLayout = (LinearLayout) view.findViewById(R.id.demo_llayout_police);

        setListen(true);
    }

    private void setListen(boolean flag) {
        if (backLayout != null) {
            backLayout.setOnClickListener(flag ? this : null);
        }
        if (consultLayout != null) {
            consultLayout.setOnClickListener(flag ? this : null);
        }
        if (policeLayout != null) {
            policeLayout.setOnClickListener(flag ? this : null);
        }

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.hn_btn_back://返回
                closeForm();
                OnDestroy();
                break;
            case R.id.demo_llayout_consult://协商定责
                Intent cintent = new Intent(context, UserGuideActivity.class);
                cintent.putExtra("title", context.getString(R.string.consult_resp));
                cintent.putExtra("url", UserGuideActivity.CONSULT_RESP);
                context.startActivity(cintent);
                break;
            case R.id.demo_llayout_police://交警定责
                Intent pintent = new Intent(context, UserGuideActivity.class);
                pintent.putExtra("title", context.getString(R.string.police_resp));
                pintent.putExtra("url", UserGuideActivity.POLICE_RESP);
                context.startActivity(pintent);
                break;
        }
    }

    @Override
    public void OnDestroy() {
        super.OnDestroy();
        setListen(false);
        this.view = null;
    }

    @Override
    public void refresh() {

    }

    @Override
    public void refreshByTime() {

    }
}
